package com.example.userlogin;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.example.userlogin.DBController;

public class Login extends Activity {

	DBController controller = new DBController(this);
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login);
		
		//Log.d(LOGCAT,"Created");
	}
	
	public void check(View view){
		EditText userName = (EditText) findViewById(R.id.lg_unt);
		EditText password = (EditText) findViewById(R.id.lg_pat);
		
		String userNameVal = userName.getText().toString();  
        String passwordVal = password.getText().toString();  
        try{
        if(userNameVal.length() > 0 && passwordVal.length() >0)  
        {    
            if(controller.Login(userNameVal, passwordVal))  
            {  
            	Intent objIntent = new Intent(Login.this, Succ.class);
        		startActivity(objIntent);  
            }else{  
            	Intent objIntent = new Intent(Login.this, UsrActivity.class);
        		startActivity(objIntent);  
            }  
            controller.close();  
        }
        }catch(Exception e) 
        {  
        	Intent objIntent = new Intent(Login.this, Register.class);
    		startActivity(objIntent);  
        }
	}
	
}
